An enthusiastic, adaptive, and fast-learning person with a broad and acute interest in the discovery of new innovative drugs, I particularly enjoy collaborating with scientists from different disciplines to develop new skills and solve new challenges.
The Repeat method is used to generate a collection or list with the same number as repeated times based on specified index values.
Syntax
Enumerable.Repeat<int>(start, times);
Example
using System;
using System.Collections.Generic;
using System.Linq;
public class Program
{
public static void Main()
{
IEnumerable<int> range = Enumerable.Repeat<int>(50,10);
long sum = range.Aggregate((a,b) => a+b);
Console.WriteLine('List ');
range.ToList().ForEach(item => Console.Write('{0}, ',item));
Console.WriteLine('\nSum : '+sum);
}
public static bool IsPrime(int num){
for(int i=2;i<Math.Sqrt(num);i++)
if(num % i ==0 )
return false;
return true;
}
}
Output
List
50, 50, 50, 50, 50, 50, 50, 50, 50, 50,
Sum : 500
Liked By
Write Answer
Give an example of the LINQ Repeat Method.
Join MindStick Community
You have need login or register for voting of answers or question.
Ravi Vishwakarma
28-Sep-2021The Repeat method is used to generate a collection or list with the same number as repeated times based on specified index values.
Syntax
Example
Output